<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="mall.demo.mybatis.pojo.Product"%>
<%@ page import="mall.demo.mybatis.pojo.Admin"%>
<%@ page import="mall.demo.mybatis.pojo.OrderWithDetail"%>
<%@ page import="mall.demo.mybatis.pojo.Order"%>
<%@ page import="mall.demo.mybatis.pojo.OrderDetail"%>
<%@ page import="mall.demo.mybatis.domain.OrderPageBean"%>
<%@ page import="mall.demo.mybatis.service.ProductService"%>
<%@ page import="mall.demo.mybatis.service.UserService"%>
<%@ page import="mall.demo.mybatis.service.OrderService"%>
<%@ page import="mall.demo.util.SessionKeyEnum"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.ArrayList"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>管理员</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/admin.css" rel="stylesheet">
<script src="/scripts/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
</head>
<%
	//首先是获取pageBean对象
	OrderPageBean pageBean = (OrderPageBean)request.getSession().getAttribute("orderPageBean");
	//判断pageBean是否为空，如果为空，那么就是第一次访问
	if(pageBean == null) {
		pageBean = new OrderPageBean();
		pageBean.setTotalRecord((new OrderService()).getTotalOrderRecord());
		//不论登录已否，都列出商品，如果已经登录就可以实现添加购物车功能
		List<Order> pageList = (new OrderService()).getAllOrdersInPage(1, pageBean.getPageSize());
		pageBean.setPageList(pageList);
	}
	List<Order> orders = pageBean.getPageList();
	
	boolean isUserLoggedIn = false;
	Object obj = session.getAttribute(SessionKeyEnum.adminObj.name());
	if (obj != null) {
		isUserLoggedIn = true;
	}

	Admin adminInfo = null;
	if (isUserLoggedIn) {
		adminInfo = (Admin) obj;
	}
	//style="background:url('images/bg2.jpg')"
	//获取当前页面的内容，默认为第一页
%>
<body>
	<div class="container">
		<div class="top">
			<div class="top_logo">
				<h2>琳琅商城</h2>
			</div>
			<!-- 分为登录和未登录两种情况 -->
			<div class="top_userInfo">
				<%
					if (isUserLoggedIn) {
				%>
				<b>欢迎：<%=adminInfo.getLoginName()%></b>&nbsp;| <b>你的身份是:管理员</b>&nbsp;|
				<b><a href="logout.do">退出登录</a></b>
				<%
					} else {
				%>
				<b><a href="login.jsp">登录</a></b>
				<%
					}
				%>
			</div>
			<br>
			<hr>
		</div>
		<nav class="navbar navbar-default" role="navigation">
		<div>
			<ul class="nav navbar-nav">
				<li><a href="admin.jsp">用户管理</a></li>
				<li class="active"><a href="admin_order.jsp">订单管理</a></li>
				<li><a href="admin_product.jsp">商品管理</a></li>
				<li><a href="admin_product_add.jsp">添加商品</a></li>
			</ul>
		</div>
		</nav>
		<div class="user_list">
			<table>
				<tr>
					<th>订单编号</th>
					<th>订单代码</th>
					<th>用户编码</th>
					<th>订单总额</th>
					<th>订单状态</th>
					<th>最后更新时间</th>
					<th>删除订单</th>
					<th>更新订单状态</th>
				</tr>
				<%
					for(Order order : orders) {
				 %>
				 <tr>
				 	<td><%=order.getOrderId() %></td>
				 	<td><%=order.getCode() %></td>
				 	<td><%=order.getUserId() %></td>
				 	<td><%=order.getTotalPrice() %></td>
				 	<td><%=order.getStatus() %></td>
				 	<td><%=order.getLastTime() %></td>
				 	<td style="text-align:center;"><a href="deleteOrderByAdmin.do?orderId=<%=order.getOrderId() %>">删除订单</a></td>
				 	<%
				 		if("SHIPPED".equalsIgnoreCase(order.getStatus())) {
				 	 %>
				 	<td>
				 		 订单已完成!
				 	</td>
				 	 <%
				 	 	} else {
				 	  %>
				 	<td style="text-align:center;"><a href="updateOrderStatus.do?orderId=<%=order.getOrderId() %>">更新订单状态</a></td>
				 	<%
				 		}
				 	 %>
				 </tr>
				 <%
				 	}
				  %>
			</table>
		</div>
		<div class="page_code">
			<a href="orderpage.do?pagecode=1">首页</a>
			<%
				for(int i = 1; i <= pageBean.getTotalPages(); i++) {
			 %>
			 	<a href="orderpage.do?pagecode=<%=i %>"><%=i %></a>
			 <%
			 }
			  %>
			<a href="orderpage.do?pagecode=<%=pageBean.getTotalPages() %>">尾页</a>
		</div>
	</div>

</body>
</html>
